package com.ali.protobuf.more;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 自定义服务端处理器
 */
public class MyProtoBufMoreServerHandler extends SimpleChannelInboundHandler<MessagePOJO.MessageInfo> {
    /**
     * 通道读取
     */
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, MessagePOJO.MessageInfo messageInfo) {
        if (MessagePOJO.MessageInfo.DataType.USER_TYPE == messageInfo.getDataType()) {
            MessagePOJO.User user = messageInfo.getUser();
            System.out.println("接收消息，User，id：" + user.getId() + "，code：" + user.getCode() + "，name：" + user.getName());
        } else if (MessagePOJO.MessageInfo.DataType.ORDER_TYPE == messageInfo.getDataType()) {
            MessagePOJO.Order order = messageInfo.getOrder();
            System.out.println("接收消息，Order，code：" + order.getCode() + "，time：" + order.getTime());
        } else {
            System.out.println("未知类型，无法处理");
        }
    }
}
